package log

import "path/filepath"

type Option func(cfg *Config) *Config

func WithLevel(l Level) Option {
	return func(cfg *Config) *Config {
		cfg.level = l
		return cfg
	}
}

func WithCaller() Option {
	return func(cfg *Config) *Config {
		cfg.withCaller = true
		return cfg
	}
}

func WithStack() Option {
	return func(cfg *Config) *Config {
		cfg.withStack = true
		return cfg
	}
}

func WithFile(basePath string) Option {
	return func(cfg *Config) *Config {
		cfg.file.toFile = true
		if !filepath.IsAbs(basePath) {
			basePath, _ = filepath.Abs(basePath)
		}
		cfg.file.basePath = basePath
		return cfg
	}
}

func WithMinDiskSpace(minDiskSpaceSize uint64) Option {
	return func(cfg *Config) *Config {
		cfg.file.minDiskSpaceSize = minDiskSpaceSize
		return cfg
	}
}

func WithFileMaxAge(maxAge int) Option {
	return func(cfg *Config) *Config {
		cfg.file.maxAge = maxAge
		return cfg
	}
}

func AddWriter(writer EncodeWriter) Option {
	return func(cfg *Config) *Config {
		cfg.ew = append(cfg.ew, writer)
		return cfg
	}
}
